package com.uenpay.im.invokeitems.contacts;

import android.util.Log;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.im.serializations.QYXUserSerializer;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 获取好友资料
 *  @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class GetUserDetailInvokeItem extends HttpInvokeItem {

	public class GetUserDetailInvokeItemResult {
		public int status;
		public String msg;
		public QYXUserEntity user;
	}

	public GetUserDetailInvokeItemResult getOutput() {
		return (GetUserDetailInvokeItemResult) GetResultObject();
	}

	public GetUserDetailInvokeItem(String show_cust_id) {
		String url = APIConfiguration.getBaseUrl()
				+ "Cust/Cust/getCustSimpleInfo?custid=" + show_cust_id + "&"
				+ APIConfiguration.getCustIdAndToken();
		Log.e("地址：",url);
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) throws Exception {
		GetUserDetailInvokeItemResult result = new GetUserDetailInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject dataJson = json.optJSONObject("data");
			if (dataJson != null) {
				result.user = QYXUserSerializer.deserializeUser(dataJson);
			}

		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}
		return result;
	}
}
